﻿using System;
using System.Collections.Generic;
using System.Text;
using MarketSimulator.Utils.Market;
using MarketSimulator.Utils.Maps;
using jade.core;

namespace MarketSimulator.Utils.Attributes
{
    public class SellerAttributes : GeneralAttributes
    {
        #region Properties

        /// <summary>
        /// Seller + Other Attributes
        /// </summary>
        public const string SellerServiceName = "[SELLER]";
        /// <summary>
        /// Product Name | Quantity | Price per Unit
        /// </summary>
        private const string ProductInfoFormat = "[{0} | q = {1} | cost = {2}]";

        /// <summary>
        /// Product List
        /// </summary>
        public IList<Product> Products { get; set; }

        /// <summary>
        /// Seller Location
        /// </summary>
        public City Location { get; set; }

        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="location"></param>
        /// <param name="products"></param>
        public SellerAttributes(Agent agent, City location, IList<Product> products, Action<string> agentsChat) : base(agentsChat)
        {
            JadeAgent = agent;
            Location = location;
            Products = products;
        }

        #region Methods
        
        /// <summary>
        /// Register Actor
        /// </summary>
        public override void RegisterAgent()
        {
            YellowPages.RegisterService(SellerServiceName, JadeAgent);
        }

        /// <summary>
        /// Get Product Information as String
        /// </summary>
        /// <returns></returns>
        public string GetProductInfoString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (var product in Products)
            {
                stringBuilder.AppendFormat(ProductInfoFormat, product.Name, product.Quantity, product.UnitCost);
            }

            return stringBuilder.ToString();
        }

        #endregion
    }
}
